"""
@Project ：Python_Learning 
@File    ：83.删除排序链表中的重复元素.py
@IDE     ：PyCharm 
@Author  ：zhupp
@Date    ：2024/10/19 19:19 
"""
from typing import Optional

# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution:
    def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:
        dummy = ListNode(0)
        dummy.next = head
        dp = dummy
        while dp.next:
            if dp.next.next is None:
                return dummy.next
            elif dp.next.next.val == dp.next.val:
                dp.next = dp.next.next
            else:
                dp = dp.next
        return dummy.next

s = Solution()

a = ListNode(1)
b = ListNode(1)
c = ListNode(4)
d = ListNode(4)
e = ListNode(5)
a.next = b
b.next = c
c.next = d
d.next = e

res = s.deleteDuplicates(a)
print(res.val)
print(res.next.val)
print(res.next.next.val)




